<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title></title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="">
	<meta http-equiv="description" content="This is my page">
	
	<script src='${CONTEXT_PATH}/dwr/interface/paperUseService.js'></script>
	<script src='${CONTEXT_PATH}/dwr/engine.js'></script>
	<script src='${CONTEXT_PATH}/dwr/util.js'></script>
	
	<script type="text/javascript" src="${CONTEXT_PATH}/js/login/business/question/define/questionConstant.js"></script>
	
  </head>
  
  <body>
    	<s:form name="frm" id="frm" method="post" action="" namespace="">
    		<jsp:include page="/jsp/outward/business/common/menuLink.jsp">
    			<jsp:param name="menuLink" value="[{'name':'${paperFix.paper.paperName}'}, {'name':'修改问卷实例'}]"/>
    			<jsp:param name="width" value="40%"/>
    		</jsp:include>
    		
    		<s:hidden name="paperFix.id" id="paperFixId"></s:hidden>
    		<s:hidden name="paperFix.paper.id" id="paperId"></s:hidden>
    		<s:hidden name="keyJson" id="keyJson"></s:hidden>
    		
    		<table cellspacing="1" cellpadding="3" width="100%" bgcolor="#CCCCCC">
				<tr bgcolor="#FFFFFF">
					<td align="right" width="15%" class="label">
						问卷编号：
					</td>
					<td align="left" width="35%">
						<s:property value="paperFix.pfCode"/>
					</td>
					<td align="right" width="15%" class="label">
						姓名：
					</td>
					<td align="left" width="35%">
						<s:textfield id="pfName" name="paperFix.pfName" cssStyle="width:80%" maxlength="20"></s:textfield>
					</td>
				</tr>
				<tr bgcolor="#FFFFFF">
					<td align="right" class="label">
						性别：
					</td>
					<td align="left" colspan="3">
						<s:select list='#{"男":"男","女":"女"}' cssStyle="width:80px;" name="paperFix.pfSex" id="pfSex" headerKey="" headerValue="--请选择--"></s:select>
					</td>
				</tr>
			</table>
			
			<table width="100%" cellspacing="0">
    			<tr>
    				<td align="center" valign="bottom" height="30">
    					<input type="button" id="saveBtn" value="保存" class="btn" onclick="saveThis()" />
    					<input type="button" value="返回实例" class="btn" onclick="backToInstance()" />
    				</td>
    			</tr>
    		</table>
    		
    		<table width="100%" cellspacing="0">
    			<tr>
    				<td width="100px"></td>
    				<td align="left">
    					<div id="qesDiv" style="display:block-inline; width:800px;"></div>
    				</td>
    			</tr>
    			<tr>
    				<td align="left" colspan="2">
    					<div id="hiddenDiv" style="display:block-inline; width:800px;"></div>
    				</td>
    			</tr>
    			<tr>
    				<td colspan="2" height="50px"></td>
    			</tr>
    		</table>
    	</s:form>
    
    <script type="text/javascript">
	var txtCode = 'qesTxt_';
	var currentN = 0;
	var txtArray = new Array();
	var optionCollect = {};
	var qesHalfQes = {};
	var jsonList = []; //问题列表
	var focusSaveList = [];
	var answerList = [];
    
	$(function(){
		qesControlInit();
	});

	function cleanTxtVal()
	{
		var allTxt = $('#qesDiv input:text');
		allTxt.val('');
	}
	
	function qesKeyInit()
	{
		cleanTxtVal();
		var keyJson = $('#keyJson');
		var list = eval(keyJson.val());
		var len = list.length;
		for(var i = 0; i < len; i++)
		{
			var id = list[i].txtId;
			var key = list[i].qesKey;
			var txtx = $('#' + id);
			if(txtx.length > 0)
			{
				txtx.val(key);
			}
		}
		var keyHiddenEvents = $('input:hidden[name="keyHiddenEvents"]');
		var keyLen = keyHiddenEvents.length;
		for(var i = 0; i < keyLen; i++)
		{
			var khex = $(keyHiddenEvents.get(i));
			if(isNotNull(khex.val()))
			{
				try
				{
					eval(khex.val());
				}
				catch (e) {
					alert(e.message);
				}
			}
		}
	}
    
    function saveThis()
    {
    	saveFlag = 'save';
        answerList = [];
        var qesLen = jsonList.length;
        for(var i = 0; i < qesLen; i++)
		{
			var qesx = jsonList[i];
			if(SINGLE_CHOICE == qesx.qesType)
			{
				var flag = checkSaveInfo(qesx.qesCode, '');
				if(flag == false)
				{
					return;
				}
			}
			else if(NUMERIC_VALUE == qesx.qesType)
			{
				var flag = checkSaveInfo(qesx.qesCode, '');
				if(flag == false)
				{
					return;
				}
			}
			else if(MULTIPLE_CHOICE == qesx.qesType)
			{
				var flag = checkSaveInfo(qesx.qesCode, '');
				if(flag == false)
				{
					return;
				}
			}
			else if(FULL_OPEN == qesx.qesType)
			{
				var flag = checkSaveInfo(qesx.qesCode, '');
				if(flag == false)
				{
					return;
				}
			}
			else if(GROUP_SINGLE == qesx.qesType)
			{
				var groupQesList = qesx.groupQesList;
    			var ioLength = groupQesList.length;
    			for(var j = 0; j < ioLength; j++)
    			{
					var optionIndex = groupQesList[j].optionValue;
					var flag = checkSaveInfo(qesx.qesCode, optionIndex);
					if(flag == false)
					{
						return;
					}
    			}
			}
			else if(GROUP_NUMERIC == qesx.qesType)
			{
				var groupQesList = qesx.groupQesList;
    			var ioLength = groupQesList.length;
    			for(var j = 0; j < ioLength; j++)
    			{
    				var optionIndex = groupQesList[j].optionValue;
					var flag = checkSaveInfo(qesx.qesCode, optionIndex);
					if(flag == false)
					{
						return;
					}
    			}
			}
			else if(GROUP_MULTIPLE == qesx.qesType)
			{
    			var groupQesList = qesx.groupQesList;
    			var ioLength = groupQesList.length;
    			for(var j = 0; j < ioLength; j++)
    			{
					var optionIndex = groupQesList[j].optionValue;
					var flag = checkSaveInfo(qesx.qesCode, optionIndex);
					if(flag == false)
					{
						return;
					}
				}
			}
		}

		var paperFixId = $('#paperFixId');
		var pfName = $('#pfName');
		var pfSex = $('#pfSex');
		var paperFix = {'id':paperFixId.val(), 'pfName':pfName.val(), 'pfSex':pfSex.val()};
		showLoading();
        paperUseService.updatePaperFix(paperFix, answerList, function(data){
			showMsg('保存成功。');
			var keyJson = $('#keyJson');
			keyJson.val(data);
			qesKeyInit();
			hideLoading();
        });
    }

    function checkSaveInfo(qesCode, optionIndex)
    {
        try
        {
	        var oi = '';
	        if(isNotNull(optionIndex))
	        {
				oi = '_' + optionIndex;
	        }
	        var txtName = txtCode + qesCode + oi;
	        var focusEventHidden = $('#focus_' + qesCode + '_' + optionIndex);
	        var keyEventHidden = $('#key_' + qesCode + '_' + optionIndex);
			var focusFlag = 'I';
			if(isNotNull(focusEventHidden.val()))
			{
				focusFlag = eval(focusEventHidden.val()) == true ? 'Y' : 'N';
			}
			var val = qesHalfQes[qesCode];
	    	var includeFlag = qesInclude(txtName, val);
	    	if('Y' == focusFlag || 'I' == focusFlag)
	    	{
	        	var txtNormal = $('input:text[name="' + txtName + '"][fitType="normal"]');
	        	var normalLen = txtNormal.length;
	        	var normalFlag = false;
	        	var openFlag = false;
	        	var firstNormal = null;
	        	for(var i = 0; i < normalLen; i++)
	        	{
	            	var normalx = $(txtNormal.get(i));
	            	if(i == 0)
	            	{
	            		firstNormal = normalx;
	               	}
	            	if((isNotNull(normalx.val()) && 'Y' == focusFlag) || 'I' == focusFlag)
	            	{
	            		normalFlag = true;
	            		var answer = {
	            			'id':normalx.attr('id'), 
	            			'val':normalx.val(), 
	            			'ctId':normalx.attr('codeTable'), 
	            			'fitType':'normal'
	            		};
	            		answerList.push(answer);
	                }
	                if(!hasOption(normalx.attr('id'), normalx.val()))
	                {
	                	return false;
	                }
	        	}
	        	if(normalFlag == false)
	            {
	        		var subQes = '';
			    	if(isNotNull(optionIndex))
			    	{
			    		subQes = '子题' + optionIndex;
				    }
	                showMsg('请填写' + qesCode + subQes + '的答案。', function(){
	                    if(firstNormal != null)
	                    {
	                        firstNormal.focus();
	                    }
	                });
	                return false;
	            }
	        	if(includeFlag)
	        	{
	        		var txtOpen = $('input:text[name="' + txtName + '"][fitType="open"]');
	        		var openLen = txtOpen.length;
	        		var firstOpen = null;
	        		for(var i = 0; i < openLen; i++)
	            	{
	                	var openx = $(txtOpen.get(i));
	                	if(i == 0)
	                	{
	                		firstOpen = openx;
	                   	}
	                	if(isNotNull(openx.val()))
	                	{
	               			openFlag = true;
	                		var answer = {
	                			'id':openx.attr('id'), 
	                			'val':openx.val(), 
	                			'fitType':'open'
	                		};
	                		answerList.push(answer);
	                    }
	            	}
	                if(openFlag == false)
	                {
	                	var subQes = '';
				    	if(isNotNull(optionIndex))
				    	{
				    		subQes = '子题' + optionIndex;
					    }
	                    showMsg('请填写' + qesCode + subQes + '的半开放题答案。', function(){
	                    	if(firstOpen != null)
	                        {
	                    		firstOpen.focus();
	                        }
	                    });
	                    return false;
	                }
	        	}
	        }
	
	        if(!isNotNull(keyEventHidden.val()))
	        {
	            return true;
	        }
	        else if(eval(keyEventHidden.val()) == false)
	        {
	        	if(keyEventHidden.val().indexOf('.toEnd') > -1)
	        		return true;
	            return false;
	        }
        }
        catch(e)
        {
			alert(e.message);
		}
        return true;
    }
    
    function backToInstance()
    {
    	var url = realPath + '/inner/qes/paperInstanceManage.action?pvo.paperId=' + $('#paperId').val();
    	window.location.href = url;
    }
    
    function qesControlInit()
    {
    	showLoading();
    	var qesDiv = $('#qesDiv');
    	var url = 'inner/qes/questionListByPaper.action';
    	ajaxAction(url, 'post', 'frm', true, function(obj){
        	var hiddenDiv = $('#hiddenDiv');
        	hiddenDiv.html('');
        	var eventHiddenHtml = '';
    		openQesWidth = 80;
    		jsonList = obj.qesList;
    		var jsonPaper = eval(obj.jsonPaperStr);
    		var halfQesRow = jsonPaper[0].halfQesRow;
    		var fullQesRow = jsonPaper[0].fullQesRow;
    		var len = jsonList.length;
    		var html = '<table id="qesTable" width="100%" cellpadding="5" cellspacing="1" bgcolor="#CCCCCC">';
    		var level = 10;
    		for(var i = 0; i < len; i++)
    		{
    			var qesx = jsonList[i];
    			var trClass = 'class="tableRow1"';
    			if(i % 2 == 1)
    			{
    				trClass = 'class="tableRow2"';
    			}
    			html += '<tr bgcolor="#FFFFFF" ' + trClass + '><td align="left" id="td_' + qesx.qesCode + '">';
    			if(SINGLE_CHOICE == qesx.qesType)
    			{
	    			html += qesx.qesCode + '.' + qesx.qesTitle + ': ';
	    			var txtName = txtCode + qesx.qesCode;
	    			var txtId = txtCode + qesx.qesCode + '_sc_';
   					html += '<input fitType="normal" type="text" id="' + txtId + '" name="' + txtName + '" onfocus="qesFocus(\'' + txtId + '\', \'\')" onkeyup="qesKeyup(\'' + txtId + '\', \'\')" style="width:' + (qesx.width * level) + 'px;" maxlength="' + qesx.width + '" onblur="txtBlur()" codeTable="' + qesx.codeTable.id + '" /> ';
					txtArray.push(txtId);
   					if(qesx.codeTable != null && 'Y' == qesx.codeTable.hasHalfQes)
   					{
   						html += '<br/>其他文本: ';
   						for(var j = 0; j < halfQesRow; j++)
   						{
   							var txtName = txtCode + qesx.qesCode;
   			    			var txtId = txtCode + qesx.qesCode + '_sct_' + j;
   							html += '<br/> <input fitType="open" type="text" id="' + txtId + '" name="' + txtName + '" onfocus="qesFocus(\'' + txtId + '\', \'\')" onkeyup="qesKeyup(\'' + txtId + '\', \'\')" style="width:' + (openQesWidth * level) + 'px;" maxlength="' + openQesWidth + '" />';
   							txtArray.push(txtId);
   	   					}
   					}
   					addOptionToCollect(qesx.qesCode, qesx.optionList);
   					addHalfQesToCollect(qesx);
   					eventHiddenHtml += eventHiddenStr(qesx.qesCode, qesx.focusEvent, qesx.keyEvent, qesx.qesType);
    			}
    			else if(NUMERIC_VALUE == qesx.qesType)
    			{
    				html += qesx.qesCode + '.' + qesx.qesTitle + ': ';
    				var txtName = txtCode + qesx.qesCode;
		    		var txtId = txtCode + qesx.qesCode + '_nv_';
   					html += '<input fitType="normal" type="text" id="' + txtId + '" name="' + txtName + '" onfocus="qesFocus(\'' + txtId + '\', \'\')" onkeyup="qesKeyup(\'' + txtId + '\', \'\')" style="width:' + (qesx.width * level) + 'px;" maxlength="' + qesx.width + '" /> ';
   					txtArray.push(txtId);
   					eventHiddenHtml += eventHiddenStr(qesx.qesCode, qesx.focusEvent, qesx.keyEvent, qesx.qesType);
    			}
    			else if(MULTIPLE_CHOICE == qesx.qesType)
    			{
	    			html += qesx.qesCode + '.' + qesx.qesTitle + ': ';
	    			for(var j = 0; j < qesx.quantity; j++)
	    			{
	    				var txtName = txtCode + qesx.qesCode;
			    		var txtId = txtCode + qesx.qesCode + '_mc_' + j;
    					html += '<input fitType="normal" type="text" id="' + txtId + '" name="' + txtName + '" onfocus="qesFocus(\'' + txtId + '\', \'\')" onkeyup="qesKeyup(\'' + txtId + '\', \'\')" style="width:' + (qesx.width * level) + 'px;" maxlength="' + qesx.width + '" onblur="txtBlur()" codeTable="' + qesx.codeTable.id + '" /> ';
    					txtArray.push(txtId);
    				}
    				if(qesx.codeTable != null && 'Y' == qesx.codeTable.hasHalfQes)
   					{
   						html += '<br/>其他文本: ';
   						for(var j = 0; j < halfQesRow; j++)
   						{
   							var txtName = txtCode + qesx.qesCode;
   				    		var txtId = txtCode + qesx.qesCode + '_mct_' + j;
   							html += '<br/> <input fitType="open" type="text" id="' + txtId + '" name="' + txtName + '" onfocus="qesFocus(\'' + txtId + '\', \'\')" onkeyup="qesKeyup(\'' + txtId + '\', \'\')" style="width:' + (openQesWidth * level) + 'px;" maxlength="' + openQesWidth + '" />';
   							txtArray.push(txtId);
   						}
   					}
    				addOptionToCollect(qesx.qesCode, qesx.optionList);
    				addHalfQesToCollect(qesx);
    				eventHiddenHtml += eventHiddenStr(qesx.qesCode, qesx.focusEvent, qesx.keyEvent, qesx.qesType);
    			}
    			else if(FULL_OPEN == qesx.qesType)
    			{
    				html += qesx.qesCode + '.' + qesx.qesTitle + ': ';
    				for(var j = 0; j < fullQesRow; j++)
    				{
    					var txtName = txtCode + qesx.qesCode;
			    		var txtId = txtCode + qesx.qesCode + '_fo_' + j;
   						html += '<br/> <input fitType="normal" type="text" id="' + txtId + '" name="' + txtName + '" onfocus="qesFocus(\'' + txtId + '\', \'\')" onkeyup="qesKeyup(\'' + txtId + '\', \'\')" style="width:' + (openQesWidth * level) + 'px;" maxlength="' + openQesWidth + '" />';
   						txtArray.push(txtId);
   					}
   					eventHiddenHtml += eventHiddenStr(qesx.qesCode, qesx.focusEvent, qesx.keyEvent, qesx.qesType);
    			}
    			else if(GROUP_SINGLE == qesx.qesType)
    			{
	    			html += qesx.qesCode + '.' + qesx.qesTitle + ': <br/>';
	    			var groupQesList = qesx.groupQesList;
	    			var ioLength = groupQesList.length;
	    			for(var j = 0; j < ioLength; j++)
	    			{
    					if(j >= 1)
    					{
    						html += '<br/>';
    					}
    					var optionIndex = groupQesList[j].optionValue;
	    				html += optionIndex + '.' + groupQesList[j].description + ': ';
	    				var txtName = txtCode + qesx.qesCode + '_' + optionIndex;
			    		var txtId = txtCode + qesx.qesCode + '_gs_' + optionIndex;
    					html += '<input fitType="normal" subQes="' + optionIndex + '" type="text" id="' + txtId + '" name="' + txtName + '" onfocus="qesFocus(\'' + txtId + '\', \'' + optionIndex + '\')" onkeyup="qesKeyup(\'' + txtId + '\', \'' + optionIndex + '\')" style="width:' + (qesx.width * level) + 'px;" maxlength="' + qesx.width + '" onblur="txtBlur()" codeTable="' + qesx.codeTable.id + '" />';
    					txtArray.push(txtId);
    					if(qesx.codeTable != null && 'Y' == qesx.codeTable.hasHalfQes)
    					{
    						html += '<br/>其他文本: ';
    						for(var k = 0; k < halfQesRow; k++)
    						{
    							var txtName = txtCode + qesx.qesCode + '_' + optionIndex;
    				    		var txtId = txtName + '_gst_' + optionIndex + '_' + k;
    							html += '<br/> <input fitType="open" type="text" id="' + txtId + '" name="' + txtName + '" onfocus="qesFocus(\'' + txtId + '\', \'' + optionIndex + '\')" onkeyup="qesKeyup(\'' + txtId + '\', \'' + optionIndex + '\')" style="width:' + (openQesWidth * level) + 'px;" maxlength="' + openQesWidth + '" />';
    							txtArray.push(txtId);
    						}
    					}
    					eventHiddenHtml += eventHiddenStr(qesx.qesCode, groupQesList[j].focusEvent, groupQesList[j].keyEvent, qesx.qesType, optionIndex);
        			}
	    			addOptionToCollect(qesx.qesCode, qesx.optionList);
	    			addHalfQesToCollect(qesx);
    			}
    			else if(GROUP_NUMERIC == qesx.qesType)
    			{
	    			html += qesx.qesCode + '.' + qesx.qesTitle + ': <br/>';
	    			var groupQesList = qesx.groupQesList;
	    			var ioLength = groupQesList.length;
	    			for(var j = 0; j < ioLength; j++)
	    			{
	    				if(j >= 1)
    					{
    						html += '<br/>';
    					}
    					var optionIndex = groupQesList[j].optionValue;
	    				html += optionIndex + '.' + groupQesList[j].description + ': ';
	    				var txtName = txtCode + qesx.qesCode + '_' + optionIndex;
			    		var txtId = txtCode + qesx.qesCode + '_gn_' + optionIndex;
    					html += '<input fitType="normal" subQes="' + optionIndex + '" type="text" id="' + txtId + '" name="' + txtName + '" onfocus="qesFocus(\'' + txtId + '\', \'' + optionIndex + '\')" onkeyup="qesKeyup(\'' + txtId + '\', \'' + optionIndex + '\')" style="width:' + (qesx.width * level) + 'px;" maxlength="' + qesx.width + '" />';
    					txtArray.push(txtId);
    					eventHiddenHtml += eventHiddenStr(qesx.qesCode, groupQesList[j].focusEvent, groupQesList[j].keyEvent, qesx.qesType, optionIndex);
    				}
    			}
    			else if(GROUP_MULTIPLE == qesx.qesType)
    			{
	    			html += qesx.qesCode + '.' + qesx.qesTitle + ': <br/>';
	    			var groupQesList = qesx.groupQesList;
	    			var ioLength = groupQesList.length;
	    			for(var j = 0; j < ioLength; j++)
	    			{
	    				if(j >= 1)
    					{
    						html += '<br/>';
    					}
    					var optionIndex = groupQesList[j].optionValue;
	    				html += optionIndex + '.' + groupQesList[j].description + ': ';
	    				for(var k = 0; k < qesx.quantity; k++)
	    				{
	    					var txtName = txtCode + qesx.qesCode + '_' + optionIndex;
				    		var txtId = txtCode + qesx.qesCode + '_gm_' + optionIndex + '_' + k;
    						html += '<input fitType="normal" subQes="' + optionIndex + '" type="text" id="' + txtId + '" name="' + txtName + '" onfocus="qesFocus(\'' + txtId + '\', \'' + optionIndex + '\')" onkeyup="qesKeyup(\'' + txtId + '\', \'' + optionIndex + '\')" style="width:' + (qesx.width * level) + 'px;" maxlength="' + qesx.width + '" onblur="txtBlur()" codeTable="' + qesx.codeTable.id + '" /> ';
    						txtArray.push(txtId);
    					}
    					if(qesx.codeTable != null && 'Y' == qesx.codeTable.hasHalfQes)
    					{
    						html += '<br/>其他文本: ';
    						for(var k = 0; k < halfQesRow; k++)
    						{
    							var txtName = txtCode + qesx.qesCode + '_' + optionIndex;
    				    		var txtId = txtName + '_gmt_' + optionIndex + '_' + k;
    							html += '<br/> <input fitType="open" type="text" id="' + txtId + '" name="' + txtName + '" onfocus="qesFocus(\'' + txtId + '\', \'' + optionIndex + '\')" onkeyup="qesKeyup(\'' + txtId + '\', \'' + optionIndex + '\')" style="width:' + (openQesWidth * level) + 'px;" maxlength="' + openQesWidth + '" />';
    							txtArray.push(txtId);
    						}
    					}
    					eventHiddenHtml += eventHiddenStr(qesx.qesCode, groupQesList[j].focusEvent, groupQesList[j].keyEvent, qesx.qesType, optionIndex);
    				}
	    			addOptionToCollect(qesx.qesCode, qesx.optionList);
	    			addHalfQesToCollect(qesx);
    			}
    			html += '</td></tr>';
    		}
    		html += '</table>';
    		qesDiv.html(html);
    		hiddenDiv.html(eventHiddenHtml);
    		
    		txtArray.push('end');
    		hideLoading();

    		qesKeyInit();
    	});
    }

    function qesFocus(id, optionIndex)
    {
    	saveFlag = 'key';
        currentN = getIndex(id);
        var flag = hasFixHalfQesOption(id);
        var qesCode = id.split('_')[1];
		var focusHiddenx = $('#focus_' + qesCode + '_' + optionIndex);
		try
		{
	        if(flag == false || (isNotNull(focusHiddenx.val()) && !eval(focusHiddenx.val())))
	        {
	        	var next = currentN + 1;
	        	var nextId = txtArray[next];
	        	var nextTxt = $('#' + nextId);
	        	if(nextTxt.length > 0)
	        	{
	        		nextTxt.focus();
	        	}
	        	else
	        	{
	            	$('BODY').focus();
	        	}
	        }
		}
		catch(e)
		{
			alert(e.message);
		}
		
		if(id.indexOf('_sc_') > -1 ||
			id.indexOf('_mc_') > -1 ||
			id.indexOf('_gs_') > -1 ||
			id.indexOf('_gm_') > -1)
		{
			optionList = optionCollect[qesCode];
			var opLen = optionList.length;
			var htm = '<table>';
			for(var i = 0; i < opLen; i++)
			{
				htm += '<tr><td>';
				htm += optionList[i].optionValue + '.' + optionList[i].description + '<br/>';
				htm += '</td></tr>';
			}
			htm += '</table>';
			showDivDesc(id, htm);
		}
    }

    function txtBlur()
    {
    	hideDivDesc();
    }

    function qesKeyup(id, optionIndex)
    {
    	var event = window.event;
	    var qesTxt_x = $('#' + id);
        if((qesTxt_x.val().length == parseInt(qesTxt_x.attr('maxlength')) || '13' == event.keyCode)
                && hasOption(id, qesTxt_x.val())
                && checkNotRepeat(id, qesTxt_x.val()))
        {
        	var qesCode = id.split('_')[1];
	        var focusHidd = $('#focus_' + qesCode + '_' + optionIndex);
	        if((NUMERIC_VALUE == focusHidd.attr('qesType') || GROUP_NUMERIC == focusHidd.attr('qesType'))
	        	&& isNotNull(qesTxt_x.val()) && checkFloat(qesTxt_x) == false)
	        {
	        	showMsg('必须为数值型。', function(){
	        		qesTxt_x.focus();
	        	});
	        	qesTxt_x.val('');
	        	return;
	        }
			var keyHiddenx = $('#key_' + qesCode + '_' + optionIndex);
			try
			{
				if(!isNotNull(keyHiddenx.val()) || eval(keyHiddenx.val()))
				{
	            	var pre = getIndex(id);
					var next = pre + 1;
		            var qesTxt_next = $('#' + txtArray[next]);
		            if(qesTxt_next.length != 0)
		            {
		            	var qesCode = txtArray[pre].split('_')[1];
		            	var txtType = txtArray[pre].split('_')[2];
		            	var sameClass = txtCode + qesCode + '_' + txtType + '_';
		            	while(txtArray[next].indexOf(sameClass) > -1 && !isNotNull(qesTxt_x.val()))
		            	{
		            		next++;
		            	}
		            	qesTxt_next = $('#' + txtArray[next]);
		            	if(qesTxt_next.length != 0)
		            	{
		            		qesTxt_next.focus();
		            	}
		            }
				}
			}
			catch(e)
			{
				alert(e.message);
			}
        }
    }

    function getIndex(id)
    {
        var len = txtArray.length;
        for(var i = 0; i < len; i++)
        {
            if(txtArray[i] == id)
            {
                return i;
            }
        }
        return -1;
    }

    function addOptionToCollect(qesCode, list)
    {
        var len = list.length;
        var arr = new Array();
        for(var i = 0; i < len; i++)
        {
            var obj = {'optionValue':list[i].optionValue, 'description':list[i].description};
            arr.push(obj);
        }
        optionCollect[qesCode] = arr;
    }

    function hasOption(txtId, value)
    {
        var txtx = $('#' + txtId);
        var qesCode = txtx.attr('name').split('_')[1];
        var arr = optionCollect[qesCode];
        if(arr == null)
        {
            return true;
        }
        var len = arr.length;
        for(var i = 0; i < len; i++)
        {
            if(!isNotNull(value)
                    || arr[i].optionValue == value 
                    || txtId.indexOf('_sct_') > -1 
                    || txtId.indexOf('_mct_') > -1 
                    || txtId.indexOf('_gst_') > -1 
                    || txtId.indexOf('_gmt_') > -1)
            {
                return true;
            }
        }
        showMsg(qesCode + '没有选项' + value + '。', function(){txtx.focus();});
        txtx.val('');
        return false;
    }

    function checkNotRepeat(txtId, value)
    {
    	var txtx = $('#' + txtId);
        var txtName = txtx.attr('name');
        var qesTxt = $('input:text[name="' + txtName + '"]');
        var len = qesTxt.length;
        for(var i = 0; i < len; i++)
        {
            var qesTxtx = $(qesTxt.get(i));
            if(isNotNull(qesTxtx.val()) && qesTxtx.attr('id') != txtId && qesTxtx.val() == value)
            {
            	showMsg('选项重复。', function(){txtx.focus();});
                txtx.val('');
                return false;
            }
        }
        return true;
    }
    
    function addHalfQesToCollect(qesx)
    {
    	var value = qesx.codeTable.halfQesVal;
    	qesHalfQes[qesx.qesCode] = value;
    }
    
    function hasFixHalfQesOption(txtId)
    {
    	if(txtId.indexOf('_sct_') > -1 
                || txtId.indexOf('_mct_') > -1 
                || txtId.indexOf('_gst_') > -1 
                || txtId.indexOf('_gmt_') > -1)
        {
        	var txtx = $('#' + txtId);
        	var txtName = txtx.attr('name');
        	var qesCode = txtName.split('_')[1];
        	var val = qesHalfQes[qesCode];
        	var includeFlag = qesInclude(txtName, val);
        	return includeFlag;
        }
        return true;
    }
    
    function qesInclude(txtName, val)
    {
    	var qesTxt = $('input:text[name="' + txtName + '"][fitType="normal"]');
    	var len = qesTxt.length;
    	for(var i = 0; i < len; i++)
    	{
    		var txtx = $(qesTxt.get(i));
    		if(isNotNull(txtx.val()) && txtx.val() == val)
    		{
    			return true;
    		}
    	}
    	return false;
    }

    function eventHiddenStr(qesCode, focusEvent, keyEvent, qesType, optionIndex)
    {
    	if(isNotNull(optionIndex) == false)
    	{
    		optionIndex = '';
    	}
    	if(isNotNull(focusEvent) == false)
    	{
    		focusEvent = 'true;';
    	}
    	if(isNotNull(keyEvent) == false)
    	{
    		keyEvent = '';
    	}
        var focusHidden = '<input name="focusHiddenEvents" type="hidden" id="focus_' + qesCode + '_' + optionIndex + '" value="' + focusEvent + '" qesType="' + qesType + '" />';
        focusHidden += '<input name="focusBakHiddenEvents" type="hidden" id="focusBak_' + qesCode + '_' + optionIndex + '" value="' + focusEvent + '" qesType="' + qesType + '" />';
        var keyHidden = '<input name="keyHiddenEvents" type="hidden" id="key_' + qesCode + '_' + optionIndex + '" value="' + keyEvent + '" qesType="' + qesType + '" />';
        return focusHidden + keyHidden;
    }

    function focusSaveCheck(qesCode, focusEvent, optionIndex)
    {
    	optionIndex = optionIndex == undefined ? '' : optionIndex;
    	var obj = {};
    	var flag = true;
    	if(isNotNull(focusEvent))
    	{
			flag = eval(focusEvent);
        }
        obj.flag = flag;
        obj.qesCode = qesCode;
        obj.optionIndex = optionIndex;
    	focusSaveList.push(obj);
    }
    </script>
    
    <script type="text/javascript" src="${CONTEXT_PATH}/js/login/business/question/use/events.js"></script>
  </body>
</html>
